# Copyright (c) 2025 Huawei Technologies Co., Ltd.
# openUBMC is licensed under Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
#         http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
from conans import ConanFile, tools
from conan.tools.files import apply_conandata_patches, export_conandata_patches

class LuacovConan(ConanFile):
    name = "luacov"
    license = "Mulan PSL v2"
    description = "LuaCov is a simple coverage analyzer for Lua code."
    settings = "os", "arch", "compiler"

    @property
    def _source_subfolder(self):
        return "source_subfolder"
    
    def source(self):
        git = tools.Git(verify_ssl=False)
        source_data = self.conan_data["sources"][self.version]
        url = source_data.get("url")
        branch = source_data.get("branch")
        shallow = source_data.get("shallow")
        reset = source_data.get("reset")
        git.clone(url=url, branch=branch, shallow=shallow)
        if reset:
            git.run(f"reset --hard {reset}")

    def export_sources(self):
        export_conandata_patches(self)

    def build(self):
        apply_conandata_patches(self)

    def package(self):
        self.copy("*", src="src", dst="opt/bmc/lualib/luacov")
